package org.jeecg.modules.xxgx.cxtj.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.common.util.LoginUserUtil;
import org.jeecg.modules.xxgx.common.util.ExcelUtils;
import org.jeecg.modules.xxgx.cxtj.param.XxFptjDwdParam;
import org.jeecg.modules.xxgx.cxtj.service.ICsXxFptjDwdService;
import org.jeecg.modules.xxgx.cxtj.vo.XxFptjDwdDTO;
import org.jeecg.modules.xxgx.kpzdgl.service.ICsXxKpzdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags="发票统计")
@RestController
@RequestMapping("/xxgx/fptj")
@Slf4j
public class CsXxFptjDwdController {
    @Autowired
    private ICsXxFptjDwdService fptjDwdService;
    @Autowired
    private ICsXxKpzdService kpzdService;


    @AutoLog(value = "发票统计-多维度")
    @ApiOperation(value="发票统计-多维度", notes="发票统计-多维度")
    @PostMapping(value = "/fptjDwd")
    public Result<List<XxFptjDwdDTO>> fptjDwd(@RequestBody XxFptjDwdParam param) {
        if(StringUtils.isEmpty(param.getTjfs())) {
            return Result.error("请选择统计维度");
        }
        if(StringUtils.isEmpty(param.getSysOrgCode())){
            String nsrsbh = LoginUserUtil.getQyxxByLoginUser().getNsrsbh();
            param.setXfsh(nsrsbh);
        } else {
            param.setSysOrgCodeArr(param.getSysOrgCode().split(","));
        }
        List<XxFptjDwdDTO> list = fptjDwdService.getXxFpxxtjDwd(param);
        return Result.OK(list);
    }

    @ApiOperation(value="发票统计-按税额-导出excel", notes="发票统计-按税额-导出excel")
    @RequestMapping(value = "/fptjDwdExportXls", method = RequestMethod.POST)
    public void fptjDwdExportXls(HttpServletRequest request, HttpServletResponse response, @RequestBody XxFptjDwdParam param) {
        if(StringUtils.isEmpty(param.getTjfs())) {
            return ;
        }
        if(StringUtils.isEmpty(param.getSysOrgCode())){
            String nsrsbh = LoginUserUtil.getQyxxByLoginUser().getNsrsbh();
            param.setXfsh(nsrsbh);
        } else {
            param.setSysOrgCodeArr(param.getSysOrgCode().split(","));
        }

        List<XxFptjDwdDTO> list = fptjDwdService.getXxFpxxtjDwd(param);
        String title = "发票统计";
        ExcelUtils.exportExcel(list,title,title,XxFptjDwdDTO.class,title,response);
    }
}
